package edu.zzuli.test.service.impl;

import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 * Created by Chen-D.W on 2018/3/6.
 */
@Service
public class ThumbnailServiceImpl implements edu.zzuli.test.service.ThumbnailService {

    public static final int WIDTH=100;

    public static final int HEIGHT=100;

    @Override
    public String thumbnail(CommonsMultipartFile file, String uploadPath, String realUploadPath){

        try {

            String des=realUploadPath+"/thum"+file.getOriginalFilename();

            Thumbnails.of(file.getInputStream()).size(WIDTH,HEIGHT).toFile(des);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return uploadPath+"/thum"+file.getOriginalFilename();

    }
}
